package m2_work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

import java.util.Scanner;

public class Producer {
    public static void main(String[] args) throws Exception{
        //创建连接
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.126.129");
        factory.setUsername("admin");
        factory.setPassword("admin");

        //创建通道
        Channel channel = factory.newConnection().createChannel();
        //定义队列，第二个参数设置为true，表示该队列是持久化队列
        channel.queueDeclare("task_queue",true,false,false,null);

        //发送消息
        while (true){
            System.out.println("输入消息：");
            String msg = new Scanner(System.in).nextLine();
            //第三个参数设置消息持久化属性
            channel.basicPublish("","task_queue", MessageProperties.PERSISTENT_TEXT_PLAIN,msg.getBytes());
        }
    }
}
